﻿using System.Collections;

namespace YaP.Library
{
    public class userComparer : IComparer
    {
        #region IComparer Members

        public int Compare(object x, object y)
        {
            IrcUser usera = (IrcUser) x;
            IrcUser userb = (IrcUser) y;

            if ((usera.IsOpped) && (userb.IsOpped))
            {
                return string.Compare(usera.name, userb.name);
            }
            else if ((usera.IsOpped) && (!(userb.IsOpped)))
                return 1;
            else if ((usera.IsHalfOp) && (userb.IsHalfOp))
            {
                return string.Compare(usera.name, userb.name);
            }
            else if ((usera.IsHalfOp) && (!(userb.IsHalfOp)) && (!(userb.IsOpped)))
                return 1;
            else if ((usera.IsVoiced) && (userb.IsVoiced))
            {
                return string.Compare(usera.name, userb.name);
            }
            else if ((usera.IsVoiced) && (!(userb.IsHalfOp)) && (!(userb.IsOpped)))
                return 1;
            else if ((userb.IsHalfOp) || (userb.IsOpped) || (userb.IsVoiced))
                return -1;
            else
            {
                return string.Compare(usera.name, userb.name);
            }

            return 0;
        }

        #endregion
    }
}